package shapes.shapes2D.polygon.triangle 
{
	import flash.geom.Point;
	import shapes.shapes2D.polygon.Edge;
	import shapes.shapes2D.polygon.Intersection;
	import utils.GeomUtils;
	/**
	 * @author Nicolas Barradeau
	 * http://en.nicoptere.net
	 */
	public class TriangleUtils 
	{
		
		public function TriangleUtils() 
		{
		}
		
		
		static public function centroid( triangle:Triangle ):Point
		{
			return new Point( 	( triangle.p0.x + triangle.p0.x + triangle.p0.x ) * 1 / 3, 
								( triangle.p1.x + triangle.p1.x + triangle.p1.x ) * 1 / 3 );
			
		}
		
		static public function gravityCenter( triangle:Triangle ):Point
		{
			
			var a:Edge = new Edge( triangle.p0, triangle.edges[1].center );
			var b:Edge = new Edge( triangle.p1, triangle.edges[2].center );
			var g:Point = Intersection.lineIntersectLine( a.p0, a.p1, b.p0, b.p1 );
			return g;
			
		}
		
		static public function median( triangle:Triangle, id:int ):Edge
		{
			
			switch( id )
			{
				case 0: return new Edge( triangle.p0, triangle.edges[1].center );
				case 1: return new Edge( triangle.p1, triangle.edges[2].center );
				case 2: return new Edge( triangle.p2, triangle.edges[0].center );
			}
			return null;
			
		}
		
		static public function height( triangle:Triangle, id:int ):Edge
		{
			
			switch( id )
			{
				case 0: return new Edge( tri.edges[ 0 ].center,  tri.p1 ).rightNormal;
				case 1: return new Edge( tri.edges[ 1 ].center,  tri.p2 ).rightNormal;
				case 2: return new Edge( tri.edges[ 2 ].center,  tri.p0 ).rightNormal;
			}
			return null;
			
		}
		
	}

}